/**
 * Copyright (C), 2018 store
 * Encoding: UTF-8
 * Date: 19-4-23 下午6:05
 * History:
 */
package com.swak.frame.api.filter.spi;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.swak.frame.chain.FilterInvoker;
import com.swak.frame.context.ApiContext;
import com.swak.frame.context.ApiContextHolder;
import com.swak.frame.context.BoundContext;
import com.swak.frame.context.SystemClock;
import com.swak.frame.filter.ApiFilter;

/**
 * ChannelContextFilter.java 上下文
 * 
 * @author ColleyMa
 * @version 19-4-23 下午6:05
 */
public class ContextFilter implements ApiFilter {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Override
	public void doFilter(BoundContext context, FilterInvoker<BoundContext> nextFilter) {
		
		logger.info("start doFilter:{}", DateTime.now().toString());
		
		context.getRequest().setAppId(context.getAppId());
		context.getRequest().setChannelId(context.getChannelId());
		ApiContext apiContext = new ApiContext(context.getToken(), context.getChannelId(), context.getAppId());
		ApiContextHolder.set(apiContext);
		SystemClock.set(context.getRequest().getFutureTime());
		//下一个流程
		nextFilter.invoke(context);
	}
}
